<?php ob_start(); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <?php
        include_once 'inc/global.php';

        $tid = isset($_GET['t']) ? $_GET['t'] : 1;
        $id = $_GET['id'];
        
        $tablename = 'ats_packageprices';
        $tabletitle = 'Prices';

        $formname = 'inc/form_prices.inc';
        $gridname = 'inc/grid_prices.inc';
        ?>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><?php echo $tabletitle; ?></title>

        <link rel="stylesheet" type="text/css" href="css/easyui.css">
        <link rel="stylesheet" type="text/css" href="css/icon.css">
        <link rel="stylesheet" type="text/css" href="css/easyuiforms.css">
        <link href="css/style.css" rel="stylesheet" type="text/css" />

        <script type="text/javascript" src="../js/tiny_mce/tiny_mce.js"></script>

        <script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
        <script type="text/javascript">
            function setTinyMce() {
                tinyMCE.init({
                    // General options
                    height: "200",
                    mode : "textareas",
                    theme : "advanced",
                    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks",

                    // Theme options
                    //                    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                    //                    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                    //                    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                    //theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,visualblocks",
                    theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                    theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,link,unlink,image,|,forecolor,backcolor,|,tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap",
                    theme_advanced_toolbar_location : "top",
                    theme_advanced_toolbar_align : "left",
                    theme_advanced_statusbar_location : "bottom",
                    theme_advanced_resizing : true,

                    // Example content CSS (should be your site CSS)
                    //content_css : "../css/content.css",
                    extended_valid_elements : "hr[class|width|size|noshade]",
                    file_browser_callback : "ajaxfilemanager",
                    paste_use_dialog : false,
                    theme_advanced_resize_horizontal : true,
                    apply_source_formatting : true,
                    force_br_newlines : true,
                    force_p_newlines : false,
                    relative_urls : false,
                    remove_script_host : false,
                    oninit: function(){
                        tinyMCE.execCommand('mceRemoveControl', false, 'msg');
                    }
                });
            }
            
            var url;
            function newData(tid){
                $('#dlg').dialog('open').dialog('setTitle','New Data');
                //$('#fm').form('clear');
                setTinyMce();
                url = 'editor_save.php?t='+tid;
            }
            function editData(tid){
                var row = $('#dg').datagrid('getSelected');
                if (row){
                    setTinyMce();
                    $('#dlg').dialog('open').dialog('setTitle','Edit Data');
                    $('#fm').form('load',row);
                    url = 'editor_update.php?id='+row.id+'&t='+tid;
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: 'Please select data to edit'
                    });
                }
            }
            function saveData(){
                $('#fm').form('submit',{
                    url: url,
                    onSubmit: function(){
                        return $(this).form('validate');
                    },
                    success: function(result){
                        var result = eval('('+result+')');
                        if (result.success){
                            $('#dlg').dialog('close');
                            $('#dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.msg
                            });
                        }
                        
                        location.reload();
                    }
                });
            }
            function removeData(tid){
            
                var row = $('#dg').datagrid('getSelected');
                if (row){
                    $.messager.confirm('Confirm','Are you sure you want to remove this data?',function(r){
                        if (r){
                            $.post('editor_remove.php?t='+tid,{id:row.id},function(result){
                                if (result.success){
                                    $('#dg').datagrid('reload');
                                } else {
                                    $.messager.show({
                                        title: 'Error',
                                        msg: result.msg
                                    });
                                }
                            },'json');
                        }
                    });
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: 'Please select data to delete'
                    });
                }
            }        
        </script>
    </head>
    <body>
        <?php
        if (strlen(session_id()) < 1)
            session_start();

        if (!isset($_SESSION['tid']))
            $_SESSION['tid'] = '';

        $_SESSION['tid'] = $tid;

        if (!isset($_SESSION['packageid']))
            $_SESSION['packageid'] = '';

        $_SESSION['packageid'] = $id;
        ?>

        <table border="1" width="100%">
            <tr>
                <td width="100%">
                    <?php include $gridname; ?>
                </td>
            </tr>
        </table>

        <div id="toolbar">
            <a href="#" 
               class="easyui-linkbutton" 
               iconCls="icon-add" 
               plain="true" 
               onclick="newData(<?php echo $tid; ?>); return false;">New <?php echo $tabletitle; ?>
            </a>
            <a href="#" 
               class="easyui-linkbutton" 
               iconCls="icon-edit" 
               plain="true" 
               onclick="editData(<?php echo $tid; ?>); return false;">Edit <?php echo $tabletitle; ?>
            </a>
            <a href="#" 
               class="easyui-linkbutton" 
               iconCls="icon-remove" 
               plain="true" 
               onclick="removeData(<?php echo $tid; ?>); return false;">Delete <?php echo $tabletitle; ?>
            </a>
        </div>

        <div id="dlg"
             class="easyui-dialog"
             style="width:600px;height:400px;padding:10px 20px"
             closed="true" buttons="#dlg-buttons">

            <div class="ftitle"><?php echo $tabletitle; ?></div>
            <form id="fm" method="post" novalidate>
                <div class="fitem">
                    <label>Package id:</label>
                    <input readonly="readonly" name="xxx" value="<?php echo $id; ?>" />
                </div>
                <div class="fitem">
                    <label>Type:</label>
                    <input name="type" class="easyui-validatebox" required="true" />
                </div>
                <div class="fitem">
                    <label>Currency:</label>
                    <input name="currency" class="easyui-validatebox" required="true" />
                </div>
                <div class="fitem">
                    <label style="display: none;">Price:</label>
                    <input style="display: none;" name="price" class="easyui-validatebox" />
                </div>
                <div class="fitem">
                    <label>Price:</label>
                    <textarea id="pricetext" name="pricetext"></textarea>
                </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#"
               class="easyui-linkbutton"
               iconCls="icon-ok"
               onclick="saveData()">Save</a>

            <a href="#"
               class="easyui-linkbutton"
               iconCls="icon-cancel"
               onclick="javascript:location.reload();">Cancel</a>
        </div>
        
        <br />
        <center>
        <a href="#" onclick="window.close();">Close</a>
        </center>
        
        <?php ob_end_flush(); ?>
    </body>
</html>